package com.alex.wechat.mp.message.text.service.impl;

import java.io.Serializable;
import java.util.List;

import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alex.wechat.mp.config.WxContext;
import com.alex.wechat.mp.message.text.entity.WxTextTemplate;
import com.alex.wechat.mp.message.text.service.WxTextTemplateServiceI;
import com.gomore.jeecg.common.Assert;

/**
 * @author Debenson
 * @since 0.1
 */
@Service("wxTextTemplateService")
@Transactional
public class WxTextTemplateServiceImpl extends CommonServiceImpl implements WxTextTemplateServiceI {

  @Override
  public <T> void delete(T entity) {
    super.delete(entity);
    // 执行删除操作配置的sql增强
    this.doDelSql((WxTextTemplate) entity);
  }

  @Override
  public <T> Serializable save(T entity) {
    ((WxTextTemplate) entity).setAccountId(WxContext.getOriginalId());
    Serializable t = super.save(entity);
    // 执行新增操作配置的sql增强
    this.doAddSql((WxTextTemplate) entity);
    return t;
  }

  @Override
  public <T> void saveOrUpdate(T entity) {
    super.saveOrUpdate(entity);
    // 执行更新操作配置的sql增强
    this.doUpdateSql((WxTextTemplate) entity);
  }

  /**
   * 默认按钮-sql增强-新增操作
   * 
   * @param id
   * @return
   */
  public boolean doAddSql(WxTextTemplate t) {
    return true;
  }

  /**
   * 默认按钮-sql增强-更新操作
   * 
   * @param id
   * @return
   */
  public boolean doUpdateSql(WxTextTemplate t) {
    return true;
  }

  /**
   * 默认按钮-sql增强-删除操作
   * 
   * @param id
   * @return
   */
  public boolean doDelSql(WxTextTemplate t) {
    return true;
  }

  @Override
  public List<WxTextTemplate> getAllByAccountId(String accountId) {
    Assert.assertArgumentNotEmpty(accountId, "accountId");

    String hql = "from " + WxTextTemplate.class.getName()
        + " where accountId = ? order by templateName";
    return findByHql(hql, accountId);
  }

}